# -*- coding: utf-8 -*-
from odoo import models, api, fields, tools
from odoo.exceptions import UserError
import re


class cultivation_technique(models.Model):

    _name = "datcent.cultivation_technique"
    _description = "生产技术"
    _table = "datcent_cultivation_technique"
    _order = "sequence"
    _inherit =  ['mail.thread', 'mail.activity.mixin', 'image.mixin']

    sequence = fields.Integer(string="排序",translate = 0)
    name = fields.Char(string="生产技术名称",translate = 0)
    technique_source_id = fields.Many2one(string="技术来源",comodel_name = 'datcent.technology_source',translate = 0)
    technique_standard_id = fields.Many2one(string="技术标准",comodel_name = 'datcent.standard_category',translate = 0)
    technique_category_id = fields.Many2one(string="技术类别",comodel_name = 'datcent.technique_category',translate = 0)
    code = fields.Char(string="编码",translate = 0)
    partner_id = fields.Many2one(string="来源/发布单位",comodel_name = 'res.partner',domain = [('is_company','=',True)],translate = 0)
    datetime = fields.Date(string="发布日期",translate = 0)
    Implementation_date = fields.Date(string="实施日期",translate = 0)
    t_state = fields.Selection(string="状态",selection = [('1', '现行'), ('2', '即将实施'), ('3', '作废'), ('4', '废止')],default='1',translate = 0)
    alternative_standards = fields.Char(string="替代标准",translate = 0)
    author = fields.Char(string="作者/起草人",translate = 0)
    author_company = fields.Char(string="作者/起草人单位",translate = 0)
    image = fields.Binary(string="相关照片",translate = 0)
    crop_ids = fields.Many2many(string="关联作物",comodel_name = 'datcent.crop',translate = 0)
    crop_varieties_ids = fields.Many2many(string="关联品种",comodel_name = 'datcent.crop_varieties',translate = 0)
    detail_contents = fields.Html(string="详细介绍",translate = 0)
    attachment = fields.Many2many(string="相关附件",comodel_name = 'ir.attachment',translate = 0)
    state = fields.Selection(string="状态",selection = [('1', '草稿'), ('2', '提交'), ('3', '审核')],default='1',translate = 0)

    def button1(self):
        if self.state == '1':
            self.write({'state': '2'})
        # 审核
    def button2(self):
        if self.state == '2':
            self.write({'state': '3'})
        # 退回
    def button3(self):
        if self.state == '2':
            self.write({'state': '1'})

        # 反审核
    def button4(self):
        if self.state == '3':
            self.write({'state': '2'})
